<?php

/*
 *
 *       _/_/_/                      _/        _/_/_/_/_/
 *    _/          _/_/      _/_/    _/  _/          _/      _/_/      _/_/
 *   _/  _/_/  _/_/_/_/  _/_/_/_/  _/_/          _/      _/    _/  _/    _/
 *  _/    _/  _/        _/        _/  _/      _/        _/    _/  _/    _/
 *   _/_/_/    _/_/_/    _/_/_/  _/    _/  _/_/_/_/_/    _/_/      _/_/
 *
 *
 *  Copyright 2013-2014, Geek Zoo Studio
 *  http://www.ecmobile.cn/license.html
 *
 *  HQ China:
 *    2319 Est.Tower Van Palace
 *    No.2 Guandongdian South Street
 *    Beijing , China
 *
 *  U.S. Office:
 *    One Park Place, Elmira College, NY, 14901, USA
 *
 *  QQ Group:   329673575
 *  BBS:        bbs.ecmobile.cn
 *  Fax:        +86-10-6561-5510
 *  Mail:       info@geek-zoo.com
 */
include_once(EC_PATH . '/includes/lib_order.php');

$mobile_phone = _POST('mobile_phone');
#$name = _POST('name');
$password = _POST('password');

if (defined('DEBUG_MOD'))
{
	logResult('************login begin*****************');
	logResult(var_export($_COOKIE, true));
	logResult(var_export($_POST, true));
}

($_user = $db->getRow('SELECT user_id,user_name FROM '.$ecs->table('users')." WHERE mobile_phone='{$mobile_phone}'")) || abort(16);

$user->login($_user['user_name'], $password) || abort(17);

$user_info = GZ_user_info($_user['user_id']);
/*
array(7) {
  ["id"]=>
  string(1) "1"
  ["name"]=>
  string(10) "b51e1c7359"
  ["rank_name"]=>
  string(12) "注册用户"
  ["rank_level"]=>
  int(0)
  ["collection_num"]=>
  int(0)
  ["email"]=>
  string(19) "b51e1c7359@aoyun.cn"
  ["order_num"]=>
  array(4) {
    ["await_pay"]=>
    int(6)
    ["await_ship"]=>
    int(0)
    ["shipped"]=>
    int(0)
    ["finished"]=>
    int(0)
  }
}
*/

update_user_info();
recalculate_price();

if (defined('DEBUG_MOD'))
{
	logResult(var_export($out, true));
	logResult('*************login end****************');
}
$info = [
	'name' => $user_info['name'],
	'rank_name' => $user_info['rank_name'],
	'rank_level' => $user_info['rank_level'],
	'collection_num' => $user_info['collection_num'],
	'order_num' => $user_info['order_num'],
	'avatar' => get_avatar($user_info['id']).'?'.time()
];
session_start();
$info['sid'] = session_id();
session('login', true);
session('user', $info);
session('user_id', $_user['user_id']);
return $info;
